# coding:utf8
import urllib.request
from bs4 import BeautifulSoup
from Jdbc import Jdbc

class SQDownload():

    def domnload(self,url):
        #设置头信息
        header = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5702.400 QQBrowser/10.2.1893.400'
        }
        request = urllib.request.Request("http:"+url, headers=header)
        #下载网页1
        response1 = urllib.request.urlopen(request)
        #通过html.parser分析页面
        str = BeautifulSoup(response1, 'html.parser', from_encoding='utf-8')
        response1.close()
        # 获取标题
        company_name = str.find('h1').find('span')
        # 获取标签信息
        contact = str.find(id='contact').find_all('dd')
        # 获取公司基本资料
        data = str.find(id='gongshang').find_all('td')
        company = list()

        company.append(company_name.getText())
        company.append(contact[0].getText())
        company.append(contact[2].getText())
        company.append(contact[1].getText())
        company.append(contact[3].getText())
        company.append('')
        company.append('')
        company.append('')
        company.append('机械')
        company.append('')
        company.append('')
        company.append('顺企网')
        company.append('0')
        company.append('')
        # company.append(data[7].getText())
        # company.append(data[17].getText())
        # company.append(data[19].getText())
        # company.append(data[21].getText())
        # company.append(data[23].getText())
        # company.append(data[25].getText())

        jdbc = Jdbc()
        jdbc.addCompany(company)

